package com.road.spider;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @Description :
 * @FileName: PropUtils.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年3月10日 下午4:30:57
 * @Version:V1.00
 */
public class PropUtils {

	private static Properties properties;

	static {
		properties = new Properties();
		InputStream inputStream = null;
		try {
			inputStream = Thread.currentThread().getContextClassLoader()
					.getResourceAsStream("config.properties"); // properties.load(Prop.class.getResourceAsStream(fileName));
			if (inputStream == null)
				throw new IllegalArgumentException(
						"Properties file not found in classpath: config.properties");
			properties.load(new InputStreamReader(inputStream, "UTF-8"));
		} catch (IOException e) {
			throw new RuntimeException("Error loading properties file.", e);
		} finally {
			if (inputStream != null)
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
	}

	public static String getString(String key) {
		return properties.getProperty(key);
	}

	public static void main(String[] args) {
		System.out.println(getString("picSavePath"));
	}

}
